use actix_web::{web, HttpResponse, Responder};
use diesel::prelude::*;
use crate::db::models::{Task};
use crate::db::schema::tasks::dsl::*;

pub async fn list_tasks(
    pool: web::Data<db::DbPool>,
) -> impl Responder {
    // different expect imformation  benefit to test 
    let conn = pool.get().expect("Counldn't connect db pool");

    let task_lsit = web::block(move ||{
        tasks.load::<Task>(&conn)
    })
    .await
    .map_err(|e| {
        eprintln!("{}", e);
        HttpResponse::InternalServerError().finish()
    })?;

    Ok(HttpResponse::Ok().json(task_list))
}

